
//这是生产配置

const path = require("path")
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin")

module.exports = {
  //打包模式
  mode: "production", //还有development模式
  //入口文件
  entry: path.resolve(__dirname, "../src/index.js"),
  //出口文件
  output: {
    path: path.resolve(__dirname, "../bulid"),
    filename: "./js/main.js",
    publicPath: "/"
  },
  //模块配置，配置loader
  module: {
    rules: [
      //html loader
      /*       {
              test: /\.html$/i,
              use: [
                //use中loader加载是有顺序的，先下后上，注意有的loader需要按照顺序书写
                'html-loader'
              ]
            } */
      //ejs
      {
        test: /\.ejs$/,
        loader: 'ejs-loader',
        options: {
          variable: 'data',
          // interpolate : '\\{\\{(.+?)\\}\\}',
          // evaluate : '\\[\\[(.+?)\\]\\]'
        }
      },
      //cSS
      {
        test: /\.css$/i,
        use: [
          //use中loader加载是有顺序的，先下后上，注意有的loader需要按照顺序书写
          "style-loader",
          'css-loader'
        ]
      }




    ]
  },
  //插件配置
  plugins: [new HtmlWebpackPlugin({
    filename: "index.html", template: path.resolve(__dirname, "../public/index.html"), minify: {
      collapseWhitespace: true,
      keepClosingSlash: true,
      removeComments: true,
      removeRedundantAttributes: true,
      removeScriptTypeAttributes: true,
      removeStyleLinkTypeAttributes: true,
      useShortDoctype: true
    }
  }),
  new CopyWebpackPlugin({
    patterns: [{
      from: path.resolve(__dirname, "../public"),
      to: "public",
      globOptions: {
        ignore: ["**/index.html"]
      }
    }],
  }),
  ],
  //
  resolve: {
    //路径别名
    alias: {
      $v: path.resolve(__dirname, "../src/view")
    },
    //后缀名
    extensions: [".js", ".json", ".ejs"],
  },



}

